package com.my.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.my.bean.Kitchenhy;
import com.my.bean.ResultPage;
import com.my.bean.User;
import com.my.bean.VoPage;
import com.my.service.KitchenhyService;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 厨房卫生状况 前端控制器
 * </p>
 *
 * @author 闫亚茹
 * @since 2018-09-10
 */
@Controller
@RequestMapping("/kitchenhy")
public class KitchenhyController {

   @Autowired
    KitchenhyService kitchenhyService;
    Logger logger=Logger.getLogger(KitchenhyController.class);


    /**
     * 添加
     * @param param
     * @return
     */
    @RequestMapping("/addKitchenhy")
    @ResponseBody
    public  String addKitchenhy(String param,HttpSession session){
        Kitchenhy kitchenhy= JSON.parseObject(param,Kitchenhy.class);
        kitchenhy.setCreatetime(new Date().getTime());
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        kitchenhy.setAreaid(areaid);
        if (kitchenhyService.insert(kitchenhy)){
            logger.info("{addKitchenhy|保存成功}");
            return  "保存成功";
        }else{
            logger.info("{addKitchenhy|保存失败}");
            return  "保存失败";
        }
    }

    /**
     * 查询并分页
     * @param voPage
     * @return
     */
    @RequestMapping("/selectKitchenhy")
    @ResponseBody
    public ResultPage<Kitchenhy> selectFiresafety(String lin, String data, VoPage voPage, HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Map map=new HashMap();
        map.put("lin",lin);
        map.put("data",data);
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        ResultPage<Kitchenhy> resultPage = kitchenhyService.selectMyPage(map,voPage,areaid,admin);
        return resultPage;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("/delectKitchenhy")
    @ResponseBody
    public boolean delectKitchenhy(Long id){
        return  kitchenhyService.deleteById(id);
    }

    /**
     * 修改
     * @param param
     * @return
     */
    @RequestMapping("/updateKitchenhy")
    @ResponseBody
    public String updateCtheckfresh(String param){
        Kitchenhy  kitchenhy = JSONObject.parseObject(param,Kitchenhy.class);
        if(kitchenhyService.updateById(kitchenhy)){
            return  "修改成功";
        }else{
            return "修改失败";
        }

    }

    @RequestMapping("/kitchenhy")
    public String  kitchenhy(){
        return "kitchenhy";
    }
    @RequestMapping("/kitchenhy_Add")
    public String  kitchenhy_Add(){
        return "Alert/kitchenhy_Add";
    }

    @RequestMapping("/kitchenhy_Edit")
    public String  kitchenhy_Edit(){
        return "Alert/kitchenhy_Edit";
    }






}
